#ifndef ENTITY_H
#define ENTITY_H

#include "GameHelper.h"
#include "I_Physics.h"
#include "ModelRender.h"
#include "BoundingBox.h"

#define RIGHT 90.f
#define LEFT -90.f

struct InputState {
    bool left;
    bool right;
    bool space;
};

class Entity {
   private: 
      vec3 mPosition;
      vec3 mNextPos;

      vec3 mVelocity;
      vec3 mAccel;

      vec3 mInitial;

      bool mIsJumping;
      bool mIsFalling;
      bool mIsOnGround;
      
      float direction;

      std::vector<I_Physics*> forces;
      std::vector<BoundingBox> collisions;
      std::vector<ModelRender*> models;

      ModelRender* model;
      BoundingBox mask;

      InputState inputState;
    
    public:
      Entity();
      Entity(vec3 initial);
      void SetModelData(const std::string& filename, GLuint newTexture, RenderManager rManager);
      void GameLoop(float dt);
      void AddAccel(float zAccel);
      void Jump();
      void Render(bool hitbox, float dt);
      void UpdateState(std::string key, bool value);

      void AddToCollisions(BoundingBox add);
      void UpdateState();

      vec3 GetPosition() { return vec3(mPosition); }
      void SetPosition(vec3 newPosition) { mPosition = newPosition; }

      vec3 GetVelocity() { return vec3(mVelocity); }
      void SetVelocity(vec3 newVelocity) { mVelocity = newVelocity; }
      
      vec3 GetAcceleration() { return vec3(mAccel); }

      BoundingBox GetMask() { return mask; }
    
	private:
      void ApplyPhysics(float dt);
      void RoundVector();
      void TestCollisions();
      void UpdatePosition();
        
      void VarInit(vec3 initial) {
         mask = BoundingBox(vec3(0.f), vec3(0.5f, 1.4f, 0.5f));
         mPosition = initial;
         mNextPos = initial;
         mVelocity = vec3(0.f);
         mAccel = vec3(0.f);
         mIsJumping = false;
         mIsFalling = false;
         mIsOnGround = false;
         direction = RIGHT;
         model = NULL;
      }
};

#endif
